package com.ewzj.bigdata.mvp.presenter

import android.app.Application
import android.support.v7.app.AppCompatActivity
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.utils.RegExpValidatorUtils
import com.ewzj.bigdata.app.utils.RxUtils
import com.ewzj.bigdata.mvp.contract.CitySelectorActivityContract
import com.ewzj.bigdata.mvp.contract.FeedBackActivityContract
import com.ewzj.bigdata.mvp.model.bean.CitygroupBean
import com.ewzj.bigdata.mvp.model.reqbean.ReqCityBean
import com.ewzj.bigdata.mvp.model.reqbean.ReqFeedback
import com.ewzj.bigdata.mvp.model.reqbean.ReqSearchCityBean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.ewzj.bigdata.mvp.model.rspbean.CityBean
import com.ewzj.bigdata.mvp.model.rspbean.CitySearchBean
import com.ewzj.bigdata.mvp.ui.adapter.CityAdapter
import com.ewzj.bigdata.mvp.ui.adapter.HotcityAdapter
import com.google.gson.Gson
import com.jess.arms.mvp.BasePresenter
import com.jess.arms.utils.DataHelper
import com.jess.arms.utils.UiUtils
import io.reactivex.Observable
import io.reactivex.observables.GroupedObservable
import me.jessyan.rxerrorhandler.core.RxErrorHandler
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber
import java.util.*
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class FeedBackActivityPresenter @Inject constructor(val mGson: Gson, val mErrorHandler: RxErrorHandler, val application: Application, view: FeedBackActivityContract.View, model: FeedBackActivityContract.Model) : BasePresenter<FeedBackActivityContract.Model, FeedBackActivityContract.View>(model, view) {
    var context=mRootView as AppCompatActivity
    fun feedBack(email:String,content:String){
        if (email.isNullOrEmpty()){
            mRootView.showMessage("邮箱不能为空哟～")
            return
        }
        if (!RegExpValidatorUtils.isEmail(email)){
            mRootView.showMessage("邮箱格式不正确～")
            return
        }
        if (content.isNullOrEmpty()){
            mRootView.showMessage("内容不能为空～")
            return
        }
        val reqFeedback = ReqFeedback()
        reqFeedback.contact=email
        reqFeedback.content=content
        mModel.feedBack(reqFeedback).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(object :ErrorHandleSubscriber<BaseData<Any>>(mErrorHandler){
                    override fun onNext(t: BaseData<Any>?) {
                        UiUtils.SnackbarText("反馈成功")
                        context.finish()
                    }

                })
    }
}